﻿using System;
using System.Collections.Generic;
using System.Text;
using MyCadDll;
//using MyCadDll;

namespace XhPaper
{
    public class MyAutoCadObjectBase:Object
    {
        double m_top;

        public double Top
        {
            get { return m_top; }
            set { m_top = value; }
        }
       
        double m_left;
        public double Left
        {
            get { return m_left; }
            set { m_left = value; }
        }

       
        MyAutoCadObjectBase m_container;
        public MyAutoCadObjectBase Container
        {
            get { return m_container; }
            set { m_container = value; }
        }

        public MyAutoCadObjectBase()
        {
        }
        public MyAutoCadObjectBase(double left, double top, MyAutoCadObjectBase container)
        {
            m_top = top;
            m_left = left;
            m_container = container;
        }

        public virtual void MyDraw(MyCad mycad)
        {
        }
    }
    public class MyPoint : MyAutoCadObjectBase
    {
        double m_x;

        public double X
        {
            get { return m_x; }
            set { m_x = value; }
        }
        double m_y;

        public double Y
        {
            get { return m_y; }
            set { m_y = value; }
        }
        double m_z=0;

        public double Z
        {
            get { return m_z; }
            set { m_z = value; }
        }
        public MyPoint(double x, double y)
        {
            m_x = x;
            m_y = y;
            m_z = 0;
        }
        public MyPoint(double x, double y,  MyAutoCadObjectBase container)
            : base(x + container.Left, container.Top+y,container)
        {
            m_x = x;
            m_y = y;
        }
        public double[] ToArray()
        {
            return new double[] {m_x,m_y,m_z };
        }
        public double[] ToScreenArray()
        {
            return new double[] {Left,Top,m_z };
        }
        public MyPoint inflate(double dx, double dy)
        {
            double x1,y1;
            x1=X +dx;
            y1=Y + dy;
            return new MyPoint(x1, y1, Container);
        }
    }
    public class MyLine : MyAutoCadObjectBase
    {
        MyPoint m_p1;

        public MyPoint P1
        {
            get { return m_p1; }
            set { m_p1 = value; }
        }
        MyPoint m_p2;

        public MyPoint P2
        {
            get { return m_p2; }
            set { m_p2 = value; }
        }

        int m_weight=1;

        public int Weight
        {
            get { return m_weight; }
            set { m_weight = value; }
        }

        public MyLine(MyPoint p1, MyPoint p2)
        {
            if (p1.X < p2.X)
            {
                m_p1 = p1;
                m_p2 = p2;
            }
            else
            {
                if (p1.Y < p2.Y)
                {
                    m_p1 = p2;
                    m_p2 = p1;
                }
                else
                {
                    m_p1 = p1;
                    m_p2 = p2;
                }
            }
        }
        public MyLine(MyPoint p1, MyPoint p2, MyAutoCadObjectBase container)
            : base(p1.X + container.Left, container.Top+p1.Y, container)
        {
            if (p1.X < p2.X)
            {
                m_p1 = p1;
                m_p2 = p2;
            }
            else
            {
                if (p1.Y < p2.Y)
                {
                    m_p1 = p2;
                    m_p2 = p1;
                }
                else
                {
                    m_p1 = p1;
                    m_p2 = p2;
                }
            }
            base.Top = m_p1.Y + container.Top;
            base.Left = m_p1.X + container.Left;
        }
        public override void MyDraw(MyCad mycad)
        {
            base.MyDraw(mycad);
            mycad.DrawLineToCad(m_p1.ToScreenArray(), m_p2.ToScreenArray(), Weight);
        }
    }
    public class MyText : MyAutoCadObjectBase
    {
        MyPoint m_p1;
        bool m_isHorizontal = true;
        public bool IsHorizontal
        {
            get { return m_isHorizontal; }
            set { m_isHorizontal = value; }
        }

        public MyPoint P1
        {
            get { return m_p1; }
            set { m_p1 = value; }
        }
        string m_text;

        public string Text
        {
            get { return m_text; }
            set { m_text = value; }
        }
        double m_height=1.5;

        public double Height
        {
            get { return m_height; }
            set { m_height = value; }
        }
        public MyText()
        {
        }
        public MyText(MyPoint p1, string text)
        {
            m_p1 = p1;
            m_text = text;
        }
        public MyText(MyPoint p1, string text, MyAutoCadObjectBase container)
            : base(p1.X + container.Left, container.Top+p1.Y, container)
        {
            m_p1 = p1;
            m_text = text;
        }
        public override void MyDraw(MyCad mycad)
        {
            base.MyDraw(mycad);
            if (Text != string.Empty)
            {
                if (IsHorizontal)
                {
                    mycad.DrawTextToCad(P1.inflate(1, 1).ToScreenArray(), Text, Height);
                }
                else
                {
                    mycad.DrawTextToCad(P1.inflate(1, 1).ToScreenArray(), Text, Height,-3.14/2);
                }
            }

        }
       
    }
    public class MyJkbText1 : MyText
    {
        MyText m_jkbName;
        public MyText JkbName
        {
            get { return m_jkbName; }
            set { m_jkbName = value; }
        }
        MyText m_weiZhi;
        public MyText WeiZhi
        {
            get { return m_weiZhi; }
            set { m_weiZhi = value; }
        }
        MyText m_sheBeiNameI;
        public MyText SheBeiNameI
        {
            get { return m_sheBeiNameI; }
            set { m_sheBeiNameI = value; }
        }
        MyText m_caiJiI1;
        public MyText CaiJiI1
        {
            get { return m_caiJiI1; }
            set { m_caiJiI1 = value; }
        }
        MyText m_caiJiI2;
        public MyText CaiJiI2
        {
            get { return m_caiJiI2; }
            set { m_caiJiI2 = value; }
        }
        MyText m_outNameI;
        public MyText OutNameI
        {
            get { return m_outNameI; }
            set { m_outNameI = value; }
        }
        MyText m_outI;
        public MyText OutI
        {
            get { return m_outI; }
            set { m_outI = value; }
        }
        MyText m_dy;
        public MyText Dy
        {
            get { return m_dy; }
            set { m_dy = value; }
        }
        public override void MyDraw(MyCad mycad)
        {
            m_jkbName.MyDraw(mycad);
            WeiZhi.MyDraw(mycad);
            SheBeiNameI.MyDraw(mycad);
            CaiJiI1.MyDraw(mycad);
            CaiJiI2.MyDraw(mycad);
            OutNameI.MyDraw(mycad);
            OutI.MyDraw(mycad);
            Dy.MyDraw(mycad);
        }
        public virtual void SetData(int index,int count,double kgbwide,double[] l,MyAutoCadObjectBase container,double[] w)
        {
            MyPoint p = new MyPoint(l[0], (0 - w[0] - w[1]) - (index * kgbwide + w[2]), container);
            JkbName = new MyText(p, string.Empty, container);
            p = new MyPoint(l[1], (0 - w[0] - w[1]) - (index * kgbwide + w[2]), container);
            WeiZhi = new MyText(p, string.Empty, container);
            p = new MyPoint(l[2], (0 - w[0] - w[1]) - (index * kgbwide + w[2]), container);
            SheBeiNameI = new MyText(p, string.Empty, container);
            p = new MyPoint(l[3], (0 - w[0] - w[1]) - (index * kgbwide + w[2]), container);
            CaiJiI1 = new MyText(p, string.Empty, container);
            p = new MyPoint(l[4], (0 - w[0] - w[1]) - (index * kgbwide + w[2]), container);
            CaiJiI2 = new MyText(p, string.Empty, container);
            p = new MyPoint(l[5], (0 - w[0] - w[1]) - (index * kgbwide + w[2]), container);
            OutNameI = new MyText(p, string.Empty, container);
            p = new MyPoint(l[6], (0 - w[0] - w[1]) - (index * kgbwide + w[2]), container);
            OutI = new MyText(p, string.Empty, container);
            p = new MyPoint(l[7], (0 - w[0] - w[1]) - (index * kgbwide + w[2]), container);
            Dy = new MyText(p, string.Empty, container);
        }
    }
    public class MyJkbText2 : MyJkbText1
    {
        MyText m_sheBeiNameII;
        public MyText SheBeiNameII
        {
            get { return m_sheBeiNameII; }
            set { m_sheBeiNameII = value; }
        }
        MyText m_caiJiII1;
        public MyText CaiJiII1
        {
            get { return m_caiJiII1; }
            set { m_caiJiII1 = value; }
        }
        MyText m_caiJiII2;
        public MyText CaiJiII2
        {
            get { return m_caiJiII2; }
            set { m_caiJiII2 = value; }
        }
        MyText m_outNameII;
        public MyText OutNameII
        {
            get { return m_outNameII; }
            set { m_outNameII = value; }
        }
        MyText m_outII;
        public MyText OutII
        {
            get { return m_outII; }
            set { m_outII = value; }
        }
        public override void MyDraw(MyCad mycad)
        {
            base.MyDraw(mycad);
            SheBeiNameII.MyDraw(mycad);
            CaiJiII1.MyDraw(mycad);
            CaiJiII2.MyDraw(mycad);
            OutNameII.MyDraw(mycad);
            OutII.MyDraw(mycad);
        }
        public override void SetData(int index, int count, double kgbwide, double[] l, MyAutoCadObjectBase container,double[] w)
        {
            base.SetData(index, count, kgbwide, l, container,w);
            double a = w[0] + w[1];
            MyPoint p = new MyPoint(l[2], (0-a)-(index * kgbwide + 2*w[2]), container);
            SheBeiNameII = new MyText(p, string.Empty, container);
            p = new MyPoint(l[3], (0-a)-(index * kgbwide + 2*w[2]), container);
            CaiJiII1 = new MyText(p, string.Empty, container);
            p = new MyPoint(l[4], (0-a)-(index * kgbwide + 2*w[2]), container);
            CaiJiII2 = new MyText(p, string.Empty, container);
            p = new MyPoint(l[5], (0-a)-(index * kgbwide + 2*w[2]), container);
            OutNameII = new MyText(p, string.Empty, container);
            p = new MyPoint(l[6], (0-a)-(index * kgbwide + 2*w[2]), container);
            OutII = new MyText(p, string.Empty, container);
        }
    }
    public class MyJkbText3 : MyJkbText2
    {
        MyText m_sheBeiNameIII;
        public MyText SheBeiNameIII
        {
            get { return m_sheBeiNameIII; }
            set { m_sheBeiNameIII = value; }
        }
        MyText m_caiJiIII1;
        public MyText CaiJiIII1
        {
            get { return m_caiJiIII1; }
            set { m_caiJiIII1 = value; }
        }
        MyText m_caiJiIII2;
        public MyText CaiJiIII2
        {
            get { return m_caiJiIII2; }
            set { m_caiJiIII2 = value; }
        }
        MyText m_outNameIII;
        public MyText OutNameIII
        {
            get { return m_outNameIII; }
            set { m_outNameIII = value; }
        }
        MyText m_outIII;
        public MyText OutIII
        {
            get { return m_outIII; }
            set { m_outIII = value; }
        }
        public override void MyDraw(MyCad mycad)
        {
            base.MyDraw(mycad);
            SheBeiNameIII.MyDraw(mycad);
            CaiJiIII1.MyDraw(mycad);
            CaiJiIII2.MyDraw(mycad);
            OutNameIII.MyDraw(mycad);
            OutIII.MyDraw(mycad);
        }
        public override void SetData(int index, int count, double kgbwide, double[] l, MyAutoCadObjectBase container,double[] w)
        {
            base.SetData(index, count, kgbwide, l, container,w);
            double a = w[0] + w[1];
            MyPoint p = new MyPoint(l[2], (0 - a) - (index * kgbwide + 3 * w[2]), container);
            SheBeiNameIII = new MyText(p, string.Empty, container);
            p = new MyPoint(l[3], (0 - a) - (index * kgbwide + 3 * w[2]), container);
            CaiJiIII1 = new MyText(p, string.Empty, container);
            p = new MyPoint(l[4], (0 - a) - (index * kgbwide + 3 * w[2]), container);
            CaiJiIII2 = new MyText(p, string.Empty, container);
            p = new MyPoint(l[5], (0 - a) - (index * kgbwide + 3 * w[2]), container);
            OutNameIII = new MyText(p, string.Empty, container);
            p = new MyPoint(l[6], (0 - a) - (index * kgbwide + 3 * w[2]), container);
            OutIII = new MyText(p, string.Empty, container);
        }
    }
}
